package com.baizhi.controller;
import com.baizhi.entity.CmfzArticle;
import com.baizhi.lucenceservice.LucenceService;
import com.baizhi.service.CmfzArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @Author: renpu
 * @Date: 2019/2/27 19:22
 * @Description:
 */
@Controller
@RequestMapping("/Article")
public class CmfzArticleController {

    @Autowired
    private CmfzArticleService articleService;

    @Autowired
    private LucenceService lucenceService;

    @RequestMapping("/showArticle")
    @ResponseBody
    public Map showArticle(int rows,int page,Map map){

        return articleService.selectArticle(rows,page);
    }

    @RequestMapping("/updateArticle")
    @ResponseBody
    public Map updateArticle(CmfzArticle article, Map map){
        try{
            articleService.update(article);
            map.put("isupdate",true);
        }catch(Exception e){
            e.printStackTrace();
            map.put("isupdate",false);
        }
        lucenceService.resetIndex();
        return map;
    }
    @RequestMapping("/deleteMany")
    public void deleteMany(int[] ids){
        articleService.deleteMany(ids);
        lucenceService.resetIndex();
    }

    @RequestMapping("/addArticle")
    public Map addArticle(CmfzArticle article, Map map){
        try{
            articleService.addArticle(article);
            map.put("isadd",true);
        }catch (Exception e){
            e.printStackTrace();
            map.put("isadd",false);
        }
        lucenceService.resetIndex();

        return map;
    }


}
